<template>
  <div>
    <vxe-toolbar>
      <template #buttons>
        <a-button @click="refresh()">刷新</a-button>
        <a-button @click="save()">保存</a-button>
      </template>
    </vxe-toolbar>

    <vxe-table
      border
      resizable
      show-overflow
      :data="modelAlarms"
      :edit-config="{ trigger: 'click', mode: 'cell' }"
    >
      <vxe-column type="seq" width="60"></vxe-column>
      <vxe-column field="name" title="名称"></vxe-column>
      <vxe-column
        field="level"
        title="等级"
        :edit-render="{
          name: '$select',
          options: levelList,
        }"
      ></vxe-column>
    </vxe-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      modelAlarms: [],
      tableData: [],
      model:{},
      levelList: [
        { label: "1", value: 1 },
        { label: "2", value: 2 },
        { label: "3", value: 3 },
        { label: "4", value: 4 },
      ],
    };
  },
  created(){
    this.refresh()
  },
  methods: {
    save() {
      if(this.model){
        let self = this
        this.$store.dispatch("tmodel/saveTModel", this.model).finally(()=>{
          self.refresh()
        });
      }
    },
    refresh() {
      let self = this
      this.$store
        .dispatch("tmodel/refreshTModelByID", "m_smartBoxForPolice")
        .then(() => {
          let m = self.$store.state.tmodel.tmodelCache["m_smartBoxForPolice"];
          m = Object.assign({},m)
          self.model = m
          if (m) {
            let mbody
            if (m.obody) 
            {
              self.mbody = m.obody;
            } 
            else 
            {
              if (typeof m.body == "string") 
              {
                mbody = JOSN.parse(m.body);
              } 
              else 
              {
                mbody = m.body;
              }
            }
            if(mbody){
              self.modelAlarms = mbody.events
              console.log("----------",self.modelAlarms)
            }
          }
        });
    },
  },
};
</script>
<style>

.vxe-select > .vxe-input .vxe-input--inner {
    color: blue;
}
.vxe-select, .vxe-select--panel{
  color: blue;
}
</style>